<link href="${rc.getContextPath()}/manage/css/dwzCustomCss/dwz.custom.css?v=${ver}" rel="stylesheet" type="text/css">
<div class="pageContent">
    <div class="treeleft" style="width: 280px; float: left; border-right: 1px solid #D8DFE5;">
		<div class="mini-toolbar">
			<input type="text" id="workcenterSearch" /> <a class="buttonActive"
				href="javascript:void(0)" id="searchTree"><span><@label
					key='search.B'>搜索</@label></span></a>
		</div>
		<div id="menuBar" class="pBar pBarBorder">
			<ul class="toolBar">
				<li><a class="collapse" id="collapsable" title="<@label key="collapseAll.D">全部收起</@label>"><span><@label
							key="collapse.B">收起</@label></span>
				</a></li>
				<li><a class="expand" id="expandable" title="<@label key="expandAll.D">全部展开</@label>"><span><@label
							key="expand.B">展开</@label></span>
				</a></li>
			</ul>
		</div>
		<div id="workcenterTree" layoutH="68">
            <#if workCentersTree??>
            <ul class="tree treeFolder expand">
                <#list workCentersTree as workCenter>
                <li><a onclick="$(this).trigger('check');" workcenterCode="${workCenter.workCenterCode!''}" >${workCenter.workCenterText!''}</a> 
                    <#if workCenter.childrens??>
                    <ul>
                        <@macroWorkCenterTree children=workCenter.childrens />
                    </ul> 
                    </#if>
                </li> 
                </#list>
            </ul>
            </#if>
        </div>
        <!-- 递归产生树的宏定义 -->
        <#macro macroWorkCenterTree children> 
            <#if children?? && children?size gt 0> 
                <#list children as workCenter>
                <li><a onclick="$(this).trigger('check');" workcenterCode="${workCenter.workCenterCode!''}" >${workCenter.workCenterText!''}</a> 
                    <#if workCenter.childrens??>
                    <ul>
                        <@macroWorkCenterTree children=workCenter.childrens />
                    </ul> 
                    </#if>
                </li>
                </#list> 
            </#if> 
        </#macro>
    </div>
    <div style="margin-left: 281px;" class="pageContent">
        <div id="jGridForShiftingPermission" style="float: left; width: 100%;"></div>
    </div>
</div>
<script type="text/javascript">
(function($){
    var $page = DWZ.context(), $grid = $('#jGridForShiftingPermission', $page), postData = {};
    $grid.jGrid({
        layoutH: 135,
        width: 900,
        base: '${rc.getContextPath()}/manage/shiftingPermission/',
        url: 'getShiftingPermissionList',
        columns: [
            {field: 'userCode;workcenterCode', group: 'ids', type: 'checkbox', width: 22},
            {field: '_index', text: '<@label key="serialNumber.C">序号</@label>', width: 50},
            {field: 'userCode', text: '<@label key="userCode.C">用户编号</@label>', width: 100, query: true, orderTable: 's'},
            {field: 'userText', text: '<@label key="userText.C">用户名称</@label>', width: 100, query: true},
            {field: 'workcenterCode', text: '<@label key="workCenterCode.C">工作中心编号</@label>', width: 100, orderTable: 's'},
            {field: 'workcenterText', text: '<@label key="workCenterText.C">工作中心描述</@label>', width: 100},
            {field: 'createUser', text: '<@label key="createUser.C">创建人</@label>', width: 100, orderTable: 's'},
            {field: 'createDateTime', type: 'date', format: 'yyyy-MM-dd HH:mm:ss', text: '<@label key="createDateTime.C">创建时间</@label>', width: 120, orderTable: 's'}
        ],
        getQueryData: function() {
        	return postData;
        },
        gridbars: [
            {icon: 'add', text: '<@label key="add.B">新增</@label>', title: '新增工作中心权限', 
                target: 'dialog', href: 'shiftingPermission_add', data: {navTabId: "${navTabId!''}"}, mask: true, width: 640, height: 480, rel: '', 
                menuCode: "shiftingPermission_add"},
            {icon: 'delete', text: '<@label key="delete.B">删除</@label>',  
                target: 'confirmTodo', action: function(){
                    var permissions = new Array();
                    $('tbody [type=checkbox]', $grid).each(function(){
                        if (this.checked) {
                            var values = $(this).val().split(';');
                            permissions.push({
                                userCode: values[0],
                                workcenterCode: values[1]
                            });
                        }
                    });
                    if (permissions.length) {
                        alertMsg.confirm("确认要删除选择的工作中心权限吗？", {okCall: function(){
                            DWZ.ajax({
                                url: '${rc.getContextPath()}/manage/shiftingPermission/deleteShiftingPermissions',
                                data: {
                                    navTabId: '${navTabId}',
                                    shiftingPermissions: JSON.stringify(permissions)
                                },
                                success: function(){
                                	$grid.jGrid('loadData');
                                }
                            });
                        }});
                    } else {
                        alertMsg.error(DWZ.msg("alertSelectMsg"));
                    }
                },
        	menuCode: "shiftingPermission_del"}
        ]
    });
    
    $("#searchTree", $page).baseTreeSearch({
        inputTextId: "#workcenterSearch",
        alertMsg: "<@label key='Tree_search_Input.D'>输入名称进行查询</@label>", //提示内容，要考虑国际化，传自后台
        $p: $page
    });
    
    $("#collapsable", $page)._treeCollapsable({
        $p: $page
    })
    
    $("#expandable", $page)._treeExpandable({
        $p: $page
    });
    
    $('#workcenterTree .tree', $page).on('check', function(event){
    	var $target = $(event.target || event.srcElement),
    	workcenterCode = $target.attr('workcenterCode');
    	if (workcenterCode) {
    		postData = {workcenterCodes: workcenterCode};
    	}
    	$grid.jGrid('loadData');
    	postData = {};
    });
    
})(jQuery);
</script>